/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GeneralViewer.java
 *
 * Created on Jul 30, 2009, 3:29:00 PM
 *
 * @version 2.0
 */

package d20chat;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 * 
 * @author Arul Suresh
 * @version 2.1
 */
public class GeneralViewer extends javax.swing.JFrame {

	private ArrayList<CharSheet> charSheets;
	protected final JFileChooser fc;
	protected final FileFilter filter;
	D20Chat main;

	// TODO: Remove comments here to integrate into project

	/** Creates new form GeneralViewer */
	public GeneralViewer() {
		initComponents();
		charSheets = new ArrayList<CharSheet>();

		filter = new FileNameExtensionFilter("Text Files and Character Sheets", "txt", "d20");
		fc = new JFileChooser(new File("./"));
		fc.setFileFilter(filter);
	}

	public GeneralViewer(D20Chat d) {
		initComponents();
		main = d;
		charSheets = new ArrayList<CharSheet>();

		filter = new FileNameExtensionFilter("Text Files and Character Sheets", "txt", "d20");
		fc = new JFileChooser(new File("./"));
		fc.setFileFilter(filter);
	}

	public GeneralViewer(D20Chat d, String inData) {
		initComponents();
		charSheets = new ArrayList<CharSheet>();
		openSheet(inData);

		filter = new FileNameExtensionFilter("Text Files and Character Sheets", "txt", "d20");
		fc = new JFileChooser(new File("./"));
		fc.setFileFilter(filter);
	}

	public GeneralViewer(D20Chat d, File inFile) {
		initComponents();
		charSheets = new ArrayList<CharSheet>();
		openSheet(inFile);

		filter = new FileNameExtensionFilter("Text Files and Character Sheets", "txt", "d20");
		fc = new JFileChooser(new File("./"));
		fc.setFileFilter(filter);
	}

	public GeneralViewer(D20Chat d, String[] inData) {
		initComponents();
		charSheets = new ArrayList<CharSheet>();
		for (String data : inData) {
			openSheet(data);
		}

		filter = new FileNameExtensionFilter("Text Files and Character Sheets", "txt", "d20");
		fc = new JFileChooser(new File("./"));
		fc.setFileFilter(filter);
	}

	public GeneralViewer(D20Chat d, String[] inData, int indexPlayerSheet) {
		initComponents();
		charSheets = new ArrayList<CharSheet>();
		for (String data : inData) {
			openSheet(data);
		}
		setPlayerSheet(charSheets.get(indexPlayerSheet).getCharName());

		filter = new FileNameExtensionFilter("Text Files and Character Sheets", "txt", "d20");
		fc = new JFileChooser(new File("./"));
		fc.setFileFilter(filter);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabbedPane = new javax.swing.JTabbedPane();
        menuBar = new javax.swing.JMenuBar();
        file = new javax.swing.JMenu();
        newSheet = new javax.swing.JMenuItem();
        openSheet = new javax.swing.JMenuItem();
        importSheet = new javax.swing.JMenuItem();
        saveSheet = new javax.swing.JMenuItem();
        saveSheetAs = new javax.swing.JMenuItem();
        closeSheet = new javax.swing.JMenuItem();
        exitSheet = new javax.swing.JMenuItem();
        edit = new javax.swing.JMenu();
        updateTitles = new javax.swing.JMenuItem();
        setPlayerSheet = new javax.swing.JMenuItem();
        view = new javax.swing.JMenu();
        viewSkillPoints = new javax.swing.JMenuItem();
        onTop = new javax.swing.JCheckBoxMenuItem();
        help = new javax.swing.JMenu();
        viewHelp = new javax.swing.JMenuItem();

        setTitle("Character Sheet Viewer");

        tabbedPane.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tabbedPaneStateChanged(evt);
            }
        });

        file.setMnemonic('f');
        file.setText("File");

        newSheet.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        newSheet.setMnemonic('n');
        newSheet.setText("New");
        newSheet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newSheetActionPerformed(evt);
            }
        });
        file.add(newSheet);

        openSheet.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        openSheet.setMnemonic('o');
        openSheet.setText("Open");
        openSheet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openSheetActionPerformed(evt);
            }
        });
        file.add(openSheet);

        importSheet.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.ALT_MASK));
        importSheet.setMnemonic('I');
        importSheet.setText("Import");
        importSheet.setToolTipText("Import a character sheet from the Pathguy Generator");
        importSheet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                importSheetActionPerformed(evt);
            }
        });
        file.add(importSheet);

        saveSheet.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveSheet.setMnemonic('s');
        saveSheet.setText("Save");
        saveSheet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveSheetActionPerformed(evt);
            }
        });
        file.add(saveSheet);

        saveSheetAs.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK));
        saveSheetAs.setText("Save As...");
        saveSheetAs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveSheetAsActionPerformed(evt);
            }
        });
        file.add(saveSheetAs);

        closeSheet.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
        closeSheet.setText("Close Tab");
        closeSheet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeSheetActionPerformed(evt);
            }
        });
        file.add(closeSheet);

        exitSheet.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        exitSheet.setText("Exit");
        exitSheet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitSheetActionPerformed(evt);
            }
        });
        file.add(exitSheet);

        menuBar.add(file);

        edit.setMnemonic('e');
        edit.setText("Edit");

        updateTitles.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, 0));
        updateTitles.setMnemonic('u');
        updateTitles.setText("Update Titles");
        updateTitles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateTitlesActionPerformed(evt);
            }
        });
        edit.add(updateTitles);

        setPlayerSheet.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F6, 0));
        setPlayerSheet.setMnemonic('m');
        setPlayerSheet.setText("Set as Main Sheet");
        setPlayerSheet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                setPlayerSheetActionPerformed(evt);
            }
        });
        edit.add(setPlayerSheet);

        menuBar.add(edit);

        view.setMnemonic('v');
        view.setText("View");

        viewSkillPoints.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F5, 0));
        viewSkillPoints.setText("Skill Points");
        viewSkillPoints.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewSkillPointsActionPerformed(evt);
            }
        });
        view.add(viewSkillPoints);

        onTop.setText("Always On Top");
        onTop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onTopActionPerformed(evt);
            }
        });
        view.add(onTop);

        menuBar.add(view);

        help.setMnemonic('h');
        help.setText("Help");

        viewHelp.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        viewHelp.setText("View Help");
        viewHelp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewHelpActionPerformed(evt);
            }
        });
        help.add(viewHelp);

        menuBar.add(help);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 625, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void importSheetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importSheetActionPerformed
		 importSheet();
	}//GEN-LAST:event_importSheetActionPerformed
	
	public void importSheet(){
		Object[] options = { "D&D 3.5", "d20 Modern" };
		int n = JOptionPane.showOptionDialog(this,
				"Please choose the edition to import:",
				"Character Sheet Type", JOptionPane.YES_NO_OPTION,
				JOptionPane.QUESTION_MESSAGE, null, // do not use a custom Icon
				options, // the titles of buttons
				options[0]); // default button title
		
		switch(n){
		case JOptionPane.YES_OPTION: System.err.println("Not implemented");
		case JOptionPane.NO_OPTION:{
			int returnVal = fc.showOpenDialog(this);
			
			switch (returnVal) {
			case JFileChooser.APPROVE_OPTION:
				File openFile = fc.getSelectedFile();
				CharSheetViewer20 view20 = new CharSheetViewer20(this);
				try{
					view20.importFromPathguy(openFile);
				}catch (IOException e){
					e.printStackTrace();
					break;
				}
				int index20 = indexOfHash(view20.getHashCode());
				if (index20 == -1) {
					tabbedPane.add(view20.getCharName() + " P1", view20.getPage1());
					tabbedPane.add(view20.getCharName() + " P2", view20.getPage2());
					charSheets.add(view20);
					tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 2);
				} else {
					view20.dispose();
					view20 = null;
					tabbedPane.setSelectedIndex(2 * index20);
				}
				break;
			default:;break;
			}
		}
		case JOptionPane.CLOSED_OPTION:
		case JOptionPane.CANCEL_OPTION:;break;
		default: System.err.println("No Hacking.");break;
		}

	}
	
	/**
	 * Prompts the user for the desired type of character sheet, and then
	 * creates the appropriate GeneralViewer. It then adds each page to this
	 * generalized viewer's JTabbedPane.
	 */
	public void newSheet() {
		Object[] options = { "D&D 3.5", "d20 Modern" };
		int n = JOptionPane.showOptionDialog(this,
				"Please choose the type of character sheet:",
				"Character Sheet Type", JOptionPane.YES_NO_OPTION,
				JOptionPane.QUESTION_MESSAGE, null, // do not use a custom Icon
				options, // the titles of buttons
				options[0]); // default button title

		switch (n) {
		case JOptionPane.CLOSED_OPTION:
		case JOptionPane.YES_OPTION:
			CharSheetViewer35 view35 = new CharSheetViewer35(this);
			tabbedPane.add(view35.getCharName() + " P1", view35.getPage1());
			tabbedPane.add(view35.getCharName() + " P2", view35.getPage2());
			charSheets.add(view35);
			charSheets.add(view35);
			tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 2);
			break;
		case JOptionPane.NO_OPTION:
			CharSheetViewer20 view20 = new CharSheetViewer20(this);
			tabbedPane.add(view20.getCharName() + " P1", view20.getPage1());
			tabbedPane.add(view20.getCharName() + " P2", view20.getPage2());
			charSheets.add(view20);
			charSheets.add(view20);
			tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 2);
			break;
		default:
			System.out.println("No Hacking");
		}
	}

	/**
	 * Prompts the user for the desired type of character sheet, and then
	 * creates the appropriate GeneralViewer, prompting the user for the file to
	 * open. It then adds each page to this generalized viewer's JTabbedPane.
	 */
	public void openSheet() {
		File openFile = null;
		int returnVal = fc.showOpenDialog(this);
		switch (returnVal) {
		case JFileChooser.APPROVE_OPTION:
			openFile = fc.getSelectedFile();
			break;
		case JFileChooser.CANCEL_OPTION:
			;
			break;
		case JFileChooser.ERROR_OPTION:
			System.err.println("ERROR: in FileChooser");
			break;
		default:
			System.out.println("No Hacking");
			break;
		}
		try {
			openSheet(openFile);
		} catch (ArrayIndexOutOfBoundsException e) {
			System.err.println("ERROR: Invalid data in the file");
		}
	}

	public void openSheet(String inText) {
		int type;
		try {
			type = Integer.parseInt(inText.substring(0, 2));
		} catch (NumberFormatException e) {
			openSheet();
			return;
		}

		switch (type) {
		case 20:
			CharSheetViewer20 view20 = new CharSheetViewer20(this, inText);
			int index20 = indexOfHash(view20.getHashCode());
			if (index20 == -1) {
				tabbedPane.add(view20.getCharName() + " P1", view20.getPage1());
				tabbedPane.add(view20.getCharName() + " P2", view20.getPage2());
				charSheets.add(view20);
				tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 2);
			} else {
				view20.dispose();
				view20 = null;
				tabbedPane.setSelectedIndex(2 * index20);
			}
			break;
		case 35:
			CharSheetViewer35 view35 = new CharSheetViewer35(this, inText);
			int index35 = indexOfHash(view35.getHashCode());
			if (index35 == -1) {
				tabbedPane.add(view35.getCharName() + " P1", view35.getPage1());
				tabbedPane.add(view35.getCharName() + " P2", view35.getPage2());
				charSheets.add(view35);
				tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 2);
			} else {
				view35.dispose();
				view35 = null;
				tabbedPane.setSelectedIndex(2 * index35);
			}
			break;
		default:
			System.out.println("No Hacking.");
		}
	}

	public void openSheet(File inFile) {
		String inText = "";
		try {
			Scanner in = new Scanner(inFile).useDelimiter("$$$$$$");
			inText += in.next();
		} catch (FileNotFoundException e) {
			System.err.println("ERROR: File not found.");
		}

		openSheet(inText);
	}

	public void saveSheet() {
		int sel = tabbedPane.getSelectedIndex();
		charSheets.get(sel / 2).save();
	}

	public void saveSheetAs() {
		int sel = tabbedPane.getSelectedIndex();
		charSheets.get(sel / 2).saveAs();
	}

	public void closeSheet() {
		int sel = tabbedPane.getSelectedIndex();
		if (!charSheets.get(sel / 2).isPlayerSheet()) {
			String title = tabbedPane.getTitleAt(sel);
			String name = title.substring(0, title.length() - 1);
			int n = title.charAt(title.length() - 1);
			switch (n) {
			case '1':
			case '2':
				int j = tabbedPane.indexOfTab(name + "1");
				tabbedPane.removeTabAt(j);
				int k = tabbedPane.indexOfTab(name + "2");
				tabbedPane.removeTabAt(k);
				CharSheet viewClose = charSheets.remove(j / 2);
				viewClose.dispose();
				viewClose = null;
				break;
			default:
				tabbedPane.remove(tabbedPane.getSelectedIndex());
				break;
			}
		}
	}

	public int indexOfHash(int hash) {
		for (int j = 0; j < charSheets.size(); j++) {
			if (hash == charSheets.get(j).getHashCode())
				return 2 * j;
		}
		return -1;
	}

	/**
	 * Opens a new sheet using the data in inText. Checks to see if there is a
	 * character sheet already open. If not, does not open the sheet.
	 * 
	 * @deprecated Use openSheet(String inText)
	 * @param inText
	 */
	public void displaySheet(String inText) {
		if (tabbedPane.getTabCount() > 1) {
			int type = Integer.parseInt(inText.substring(0, 2));

			switch (type) {
			case 20:
				CharSheetViewer20 view20 = new CharSheetViewer20(this, inText);
				tabbedPane.add(view20.getCharName() + " P1", view20.getPage1());
				tabbedPane.add(view20.getCharName() + " P2", view20.getPage2());
				charSheets.add(view20);
				break;
			case 35:
				CharSheetViewer35 view35 = new CharSheetViewer35(this, inText);
				tabbedPane.add(view35.getCharName() + " P1", view35.getPage1());
				tabbedPane.add(view35.getCharName() + " P2", view35.getPage2());
				charSheets.add(view35);
				break;
			default:
				System.out.println("No Hacking.");
			}
		} else {
			JOptionPane.showMessageDialog(this,
					"Error:  you must have your sheet open first.");
		}
	}

	public void setSheetData(String inText, String charName) {
		int index = -1;
		for (int j = 0; j < charSheets.size(); j++) {
			if (charSheets.get(j).getCharName().equals(charName)) {
				index = j;
				break;
			}
		}

		if (index < 0 || index > charSheets.size() - 1)
			System.err.println("ERROR: Invalid name for setSheetData");
		else {
			charSheets.get(index).setData(inText);
		}
	}

	public void setSheetData(String inText, int tabIndex) {
		if (tabIndex < 0 || tabIndex > tabbedPane.getTabCount() - 1)
			System.err.println("ERROR: Invalid tab location for setSheetData");
		else {
			charSheets.get(tabIndex / 2).setData(inText);
		}
	}

	public void updateCharData(String newData) {
		main.gui.characterSheetEditorPane.setText(newData);
		main.gui.characterNameTextField.setText(newData.substring(5,
				newData.indexOf('#')));
		// TODO: Remove comments here to integrate into project
	}

	private void updateTitles() {
		if (tabbedPane.getTabCount() != 0 && charSheets.size() != 0) {
			for (int j = 0; j < tabbedPane.getTabCount(); j++) {
				CharSheet viewTitle = charSheets.get(j / 2);
				String charName = "";
				charName = viewTitle.getCharName();
				String oldName = tabbedPane.getTitleAt(j);
				tabbedPane.setTitleAt(j,
						charName + oldName.substring(oldName.length() - 3));
			}
		}
	}

	public void setPlayerSheet(String charName) {
		try {
			for (int j = 0; j < charSheets.size(); j++) {
				if (charSheets.get(j).getCharName().equals(charName))
					charSheets.get(j).setPlayerSheet(true);
				else
					charSheets.get(j).setPlayerSheet(false);
			}
		} catch (IndexOutOfBoundsException e) {
			System.err.println("ERROR: Invalid index for setPlayerSheet.");
		}
	}

	public String getPlayerSheetData() {
		for (CharSheet i : charSheets) {
			if (i.isPlayerSheet())
				return i.toString();
		}
		return "";
	}

	public String getThisPlayerRoll(String rollName) {
		for (CharSheet i : charSheets) {
			if (i.isPlayerSheet())
				return i.getRoll(rollName);
		}
		return "";
	}

	private void newSheetActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_newSheetActionPerformed
		newSheet();
	}// GEN-LAST:event_newSheetActionPerformed

	private void openSheetActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_openSheetActionPerformed
		openSheet();
	}// GEN-LAST:event_openSheetActionPerformed

	private void saveSheetActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_saveSheetActionPerformed
		saveSheet();
	}// GEN-LAST:event_saveSheetActionPerformed

	private void saveSheetAsActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_saveSheetAsActionPerformed
		saveSheetAs();
	}// GEN-LAST:event_saveSheetAsActionPerformed

	private void closeSheetActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_closeSheetActionPerformed
		closeSheet();
	}// GEN-LAST:event_closeSheetActionPerformed

	private void viewSkillPointsActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_viewSkillPointsActionPerformed
		int sel = tabbedPane.getSelectedIndex();
		if (sel != -1) {
			CharSheet viewSp = charSheets.get(sel / 2);
			int sp = 0;
			sp = viewSp.getSkillPts();

			String msg = "Total skill points used: " + sp;

			JOptionPane.showMessageDialog(this, msg, "Skill Points",
					JOptionPane.INFORMATION_MESSAGE);
		}
	}// GEN-LAST:event_viewSkillPointsActionPerformed

	private void updateTitlesActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_updateTitlesActionPerformed
		updateTitles();
	}// GEN-LAST:event_updateTitlesActionPerformed

	private void exitSheetActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_exitSheetActionPerformed
		this.setVisible(false);
	}// GEN-LAST:event_exitSheetActionPerformed

	private void viewHelpActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_viewHelpActionPerformed
		JOptionPane
				.showMessageDialog(this, "GeneralViewer  v1.7\n"
						+ "File->New: Opens a new Character Sheet.\nFile->Sa"
						+ "ve: Saves the Character sheet in the default loca"
						+ "tion.\nFile->SaveAs...: Saves the character sheet"
						+ "in the chosen location.\nFile->Open: Opens the ch"
						+ "osen character sheet.\nEdit->Update Titles: updat"
						+ "es titles to match modified character names.\nEdi"
						+ "t->Set as Main Sheet: sets the selected sheet to "
						+ "the main sheet.  The main sheet cannot be closed "
						+ "with Ctrl-W.\nView->Skill Points: Displays total "
						+ "skill points used.", "Help",
						JOptionPane.INFORMATION_MESSAGE);
	}// GEN-LAST:event_viewHelpActionPerformed

	private void setPlayerSheetActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_setPlayerSheetActionPerformed
		int sel = tabbedPane.getSelectedIndex();
		for (int j = 0; j < charSheets.size(); j++) {
			charSheets.get(j).setPlayerSheet(false);
		}
		charSheets.get(sel / 2).setPlayerSheet(true);
	}// GEN-LAST:event_setPlayerSheetActionPerformed

	private void onTopActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_onTopActionPerformed
		this.setAlwaysOnTop(onTop.isSelected());
	}// GEN-LAST:event_onTopActionPerformed

	private void tabbedPaneStateChanged(javax.swing.event.ChangeEvent evt) {// GEN-FIRST:event_tabbedPaneStateChanged
		updateTitles();
	}// GEN-LAST:event_tabbedPaneStateChanged

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String[] args) {
		GeneralViewer view = new GeneralViewer();
		view.setVisible(true);

		String test = "CharName35";
		String test2 = "CharName35";
		System.out.println(test.hashCode() + ": " + test2.hashCode());
	}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem closeSheet;
    private javax.swing.JMenu edit;
    private javax.swing.JMenuItem exitSheet;
    private javax.swing.JMenu file;
    private javax.swing.JMenu help;
    private javax.swing.JMenuItem importSheet;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem newSheet;
    private javax.swing.JCheckBoxMenuItem onTop;
    private javax.swing.JMenuItem openSheet;
    private javax.swing.JMenuItem saveSheet;
    private javax.swing.JMenuItem saveSheetAs;
    private javax.swing.JMenuItem setPlayerSheet;
    private javax.swing.JTabbedPane tabbedPane;
    private javax.swing.JMenuItem updateTitles;
    private javax.swing.JMenu view;
    private javax.swing.JMenuItem viewHelp;
    private javax.swing.JMenuItem viewSkillPoints;
    // End of variables declaration//GEN-END:variables

}
